//
//  tabletestAppDelegate.m
//  tabletest
//
//  Created by Andy on 2010/8/25.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "AppDelegate.h"
#import "Setup.h"
#import "InAppPurchase.h"
#import "navcontroller.h" 
#import "StockTableController.h"
#import "DetailViewController.h"
#import "SplitViewDelegate.h"
#import "HelpViewController.h"
#import "JSON.h"
#import "Appirater.h"
#import "HTMLNode.h"
#import "HTMLParser.h"
#import "TreeMapViewController.h"
//#import <sys/utsname.h>
NSTimeInterval timeIntervalForNumberOfWeeks(float numberOfWeeks)
{
    NSTimeInterval seconds = fabs(60.0 * 60.0 * 24.0 * 7.0 * numberOfWeeks);
    return seconds;
    
}
 
 

@implementation AppDelegate

@synthesize Split_viewController,splitViewDelegate,mv,dv , interfaceOrientation_ipad;
@synthesize  ahelp,agraph,Master_popController,popController_info,popController_info_next  ; 
@synthesize can_use_graph_setup;

#pragma mark -
#pragma mark 基礎元件設計碼

/*
 @設定 plist
 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];			
 if ([prefs  objectForKey:@"isManager"]==nil) {
     [prefs setObject:[NSNumber numberWithBool:NO]  forKey:@"isManager"];
     [prefs synchronize];		
 }	
 
 @取出設定 plist
 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
 if ([[prefs objectForKey:@"isManager"] boolValue]==YES) {
  
 }
 
 @字串處理 如何去除跳脫字元
   去除 \
   => stringByReplacingOccurrencesOfString:@"\\" withString:@""    ; 
   
   去除 "
   =>stringByReplacingOccurrencesOfString:@"\"" withString:@""  
   
 
 @字串處理 如何添加%符號
   =>stringWithFormat:@"%@%%", 
 
 @字串處理 分割
   =>NSArray * Timestamp_array=[Timestamp componentsSeparatedByString:@","];  
 
 @目錄位置：
 
   1.NSCachesDirectory     => <Application_Home>/Library/Caches
   2.NSDocumentDirectory   => <Application_Home>/Documents/ 
 
 @使用正規表示式
 1.加入RegexKitLite.h RegexKitLite.m
 2.Other Linker Flags:加入-licucore 技巧：因為之前有core plot 加入-all_load -ObjC 所以要加入 -licucore就是使用空白分隔加入 結果如下：-all_load -ObjC -licucore ，可以在projetc下加入，則可以同時全部加入target
 3.應用範例
 
   //標記:正規表示式 從文字中只取出數字
 
 @處理core plot 顏色設定 可以從photoshop 的調色盤上取出 數字
 [CPTColor colorWithComponentRed:(?/255.f) green:(?/255.f) blue:(?/255.f) alpha:1]; 
 */





#pragma mark -
#pragma mark 基礎元件設計模組

//時區模組 列出所有時區名稱
 -(void)timezone_list_knownTimeZoneNames{
    for (NSString *a in [NSTimeZone knownTimeZoneNames]) {
        NSLog(@"knownTimeZoneNames=%@",a);
    }
}

//時區模組 NSDate轉換
-(void)timezone{
    //將yahoo 的intraday 資料下載 日期格式轉換==== 
    //如何將ㄧ時區的時間轉到另外一個時區時間
    //
    NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithName:@"America/New_York"];
    if ([easternTimeZone isDaylightSavingTime]) {
        NSLog(@"East coast is NOT on DT");
    } else {
        NSLog(@"East coast is on DT");      
    }    
    
    
    for (NSString *a in [NSTimeZone abbreviationDictionary]) {
        //  NSLog(@"abbreviationDictionary=%@",a);
    }    
    
   
    NSCalendar *gregorian=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
    NSTimeZone *easternTimeZoneEDT =[ NSTimeZone  timeZoneWithAbbreviation:@"EDT"];    
    [gregorian setTimeZone:easternTimeZoneEDT];
    NSDateComponents *timeZoneComps=[[NSDateComponents alloc] init];
    [timeZoneComps setYear:2011];
    [timeZoneComps setMonth:9];
    [timeZoneComps setDay:23];
    [timeZoneComps setHour:1]; 
    [timeZoneComps setMinute:3];   
    NSDate *date_EDT=[gregorian dateFromComponents:timeZoneComps];    
    [gregorian release];    
    [timeZoneComps release];
    
    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
    [dateFormatter1 setDateFormat:@"yyyy-MM-dd HH:mm"];
    [dateFormatter1 setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EDT"]];
    NSDate *date1 = [dateFormatter1 dateFromString:@"2010-9-23 1:16" ];
    if ([easternTimeZoneEDT isDaylightSavingTimeForDate:date1]) {
        NSLog(@"yes isDaylightSavingTimeForDate");
    }
    else{
        NSLog(@"no isDaylightSavingTimeForDate");    
    }
    
    [dateFormatter1 release];
    
    float testint1;
    testint1=[date1 timeIntervalSince1970];
    NSLog(@"time1 now=%f",testint1);    
    //
    NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc]init];
    [dateFormatter2 setDateFormat:@"yyyy-MM-dd HH:mm"];
    [dateFormatter2 setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EDT"]];
    
    NSDate *date2 = [dateFormatter2 dateFromString:@"2010-12-23 3:49" ];
    [dateFormatter2 release];
    
    
    // NSDate* sourceDate = date2;
    
    // NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EDT"];
    //  NSTimeZone* destinationTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"HKT"];
    
    // NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
    // NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
    //   NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
    
    //  NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];    
    
    
    
    //
    
    
    float testint2;
    testint2=[date2 timeIntervalSince1970];
    NSLog(@"time2 now=%f",testint2);      
    
    NSDate *now1 ;
    now1=[NSDate dateWithTimeIntervalSince1970:testint1 ];      
    NSDate *now2 ;
    now2=[NSDate dateWithTimeIntervalSince1970:testint2 ];     
    
    
    
    
    NSDate *test;
    test=[NSDate date];
    float testint;
    testint=[test timeIntervalSince1970];
    NSLog(@"time now=%f",testint);
    
    //NSDate *now ;
    //now=[NSDate dateWithTimeIntervalSince1970:[@"1316698200" doubleValue ]  ];    
    
    // now=[NSDate dateWithTimeIntervalSince1970:testint  ]    ;
    
    
    NSUInteger flags=NSYearCalendarUnit |NSMonthCalendarUnit |NSDayCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit |NSSecondCalendarUnit;
    
    NSCalendar *calendar1 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSTimeZone *zone1 = [NSTimeZone timeZoneWithAbbreviation:@"HKT"];
    [calendar1 setTimeZone:zone1];    
    NSDateComponents *comp1=[calendar1 components:flags fromDate:date_EDT];
    NSLog(@"HKT1=%d/%d/%d %d:%d:%d",[comp1 year],[comp1 month],[comp1 day],[comp1 hour],[comp1 minute],[comp1 second]);
    [calendar1 release];
    
    NSCalendar *calendar2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSTimeZone *zone2 = [NSTimeZone timeZoneWithAbbreviation:@"HKT"];
    [calendar2 setTimeZone:zone2];    
    NSDateComponents *comp2=[calendar2 components:flags fromDate:now2];
    NSLog(@"HKT2=%d/%d/%d %d:%d:%d",[comp2 year],[comp2 month],[comp2 day],[comp2 hour],[comp2 minute],[comp2 second]); 
    
    [calendar2 release];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MMM-dd HH:mm:ss";
    
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"HKT"];
    [dateFormatter setTimeZone:gmt];
    
    NSString *timeStamp = [dateFormatter stringFromDate:now1];
    NSLog(@"timeStampMMM=%@",timeStamp);
    
    [dateFormatter release];    
}

#pragma mark -
#pragma mark 基礎元件設計模組 網路上免費報價資料


//Yahoo代碼搜尋 JSONValue 巢狀 運用
-(void)Yahoo_code_search{
    //此段程式可以取出當你在yahoo  finance 上的getquote 上打出的前幾個字母搜尋結果  最多搜尋十個
    
    NSString *urls=@"http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=aa&callback=YAHOO.Finance.SymbolSuggest.ssCallback" ;        
    
    
    NSURL *  urla;
    urla = [NSURL URLWithString:urls];
    
    NSError * errorq = nil;
    NSString * download_string;
    download_string=[NSString stringWithContentsOfURL:urla encoding:NSUTF8StringEncoding error:&errorq];
    
    NSLog(@"下載原始字串=%@",download_string);
    
    //去除無用的字串 '//'
    NSString *string_for_jsonvalue= [[download_string stringByReplacingOccurrencesOfString: @"YAHOO.Finance.SymbolSuggest.ssCallback(" withString:@"" ] stringByReplacingOccurrencesOfString:@")" withString:@""];
        
    //***JSONValue 巢狀******************************* 
    NSDictionary *jsonvalue_elements = [[[string_for_jsonvalue JSONValue] objectForKey:@"ResultSet"] objectForKey:@"Result"];
       
    for (NSDictionary *sss in jsonvalue_elements ) {
        NSLog(@"exch=%@",[sss objectForKey:@"exch"]  );
         NSLog(@"exchDisp=%@",[sss objectForKey:@"exchDisp"]  ); 
         NSLog(@"name=%@",[sss objectForKey:@"name"]  );         
         NSLog(@"symbol=%@",[sss objectForKey:@"symbol"]  );    
         NSLog(@"type=%@",[sss objectForKey:@"type"]  );  
         NSLog(@"typeDisp=%@",[sss objectForKey:@"typeDisp"]  );          
        
    }        
    
    
    
}

//Google資料 即時報價
-(void)Google_realtime{
    //每個股票間的分隔是用,
    
    //另外一個搜尋的模式 可以研究看看    
    //http://www.google.com/finance/info?infotype=infoquoteall&q=C,JPM,AIG
   // http://www.google.com/finance/info?infotype=infoquoteall&q=ETR:XTA,ETR:BZU,ETR:C2H,ETR:S64,ETR:ADH1,ETR:B3A,ETR:CIAH,ETR:USG1,ETR:QAN,ETR:FAI,ETR:ANCA,ETR:LHA, 
   
    NSString *urls=@"http://finance.google.com/finance/info?client=ig&q=ETR:XTA,ETR:BZU" ;        
     
    
   // NSString *urls=@"http://www.google.com/finance/info?infotype=infoquoteall&q=ETR:XTA,ETR:BZU" ;   
        
		NSURL *  urla;
		urla = [NSURL URLWithString:urls];
		
		NSError * errorq = nil;
        NSString * download_string;
      
        //標記:下載資料的編碼分兩種 因為下載歐洲股票會產生歐元符號 所以將原本的NSUTF8StringEncoding 改為NSASCIIStringEncoding      
       
     // download_string=[NSString stringWithContentsOfURL:urla encoding:NSUTF8StringEncoding error:&errorq];
        download_string=[NSString stringWithContentsOfURL:urla encoding:NSASCIIStringEncoding error:&errorq];
   
    
      NSLog(@"DOWNLOAD=%@",download_string);
      NSLog(@"ERROR=%@",errorq.description);
    
    
        //去除無用的字串 '//'
        NSString *string_for_jsonvalue= [download_string stringByReplacingOccurrencesOfString: @"//" withString:@"" ];
        
        //將字串的每個elements 分解出來      
        NSArray *jsonvalue_elements = [string_for_jsonvalue JSONValue];
        
        for (NSDictionary *s in jsonvalue_elements ) {
            NSLog(@"s=%@",s);
            //取出每個objects 的值
            NSLog(@"id=%@",[s objectForKey:@"id"]  );
            NSLog(@"t=%@",[s objectForKey:@"t"]  );            
            NSLog(@"e=%@",[s objectForKey:@"e"]  );  
            NSLog(@"l=%@",[s objectForKey:@"l"]  );            
            
        }        
        
        
    
    //各種欄位帶號說明
     {
     /*
     avvo    * Average volume (float with multiplier, like '3.54M')
     beta    * Beta (float)
     c       * Amount of change while open (float)
     ccol    * (unknown) (chars)
     cl        Last perc. change
     cp      * Change perc. while open (float)
     e       * Exchange (text, like 'NASDAQ')
     ec      * After hours last change from close (float)
     eccol   * (unknown) (chars)
     ecp     * After hours last chage perc. from close (float)
     el      * After. hours last quote (float)
     el_cur  * (unknown) (float)
     elt       After hours last quote time (unknown)
     eo      * Exchange Open (0 or 1)
     eps     * Earnings per share (float)
     fwpe      Forward PE ratio (float)
     hi      * Price high (float)
     hi52    * 52 weeks high (float)
     id      * Company id (identifying number)
     l       * Last value while open (float)
     l_cur   * Last value at close (like 'l')
     lo      * Price low (float)
     lo52    * 52 weeks low (float)
     lt        Last value date/time
     ltt       Last trade time (Same as "lt" without the data)
     mc      * Market cap. (float with multiplier, like '123.45B')
     name    * Company name (text)
     op      * Open price (float)
     pe      * PE ratio (float)
     t       * Ticker (text)
     type    * Type (i.e. 'Company')
     vo      * Volume (float with multiplier, like '3.54M')       
    */
      
     }
        
}

//Google資料 歷史資料 日線

//標記:將三個英文字母的月份轉為數字
-(int)MMM_MonthConvertToInterger:(NSString *)mmm{
    NSString *MMMs;
    MMMs=[mmm uppercaseString];
    if ([MMMs isEqualToString:[@"Jan" uppercaseString] ]) {
        return 1;
    }
    else if ([MMMs isEqualToString:[@"Feb" uppercaseString] ]) {
        return 2;
    }  
    else if ([MMMs isEqualToString:[@"Mar" uppercaseString] ]) {
        return 3;
    }  
    else if ([MMMs isEqualToString:[@"Apr" uppercaseString] ]) {
        return 4;
    }  
    else if ([MMMs isEqualToString:[@"May" uppercaseString] ]) {
        return 5;
    }  
    else if ([MMMs isEqualToString:[@"Jun" uppercaseString] ]) {
        return 6;
    }  
    else if ([MMMs isEqualToString:[@"Jul" uppercaseString] ]) {
        return 7;
    } 
    else if ([MMMs isEqualToString:[@"Aug" uppercaseString] ]) {
        return 8;
    }  
    else if ([MMMs isEqualToString:[@"Sep" uppercaseString] ]) {
        return 9;
    }  
    else if ([MMMs isEqualToString:[@"Oct" uppercaseString] ]) {
        return 10;
    }      
    else if ([MMMs isEqualToString:[@"Nov" uppercaseString] ]) {
        return 11;
    }  
    else if ([MMMs isEqualToString:[@"Dec" uppercaseString] ]) {
        return 12;
    }  
    else{
        return 0;
        
    }
    
}

//將google的日線資料全部取出 因為取出某一段時間 因為googl的日線資料僅可以取出200天 所以分段取出
-(NSMutableArray *)Google_HistoryData_Daily:(NSString *)symbols 
                            StartDates:(NSString *)ST
                              EndDates:(NSString *)ED{
    
    NSMutableArray *google_data_array;
    
    //google的每次取出資料限制
    int max_get;
    max_get=200;
    
    google_data_array=[[[NSMutableArray alloc] init] autorelease];
    
    int pre_count;
    pre_count=-1;
    
    BOOL looprun;
    looprun=YES;
    
    for (int i=0; i<30 && looprun==YES ; i++) {
        
        google_data_array=[self Google_HistoryData:google_data_array 
                                            Symbol:symbols
                                         StartDate: ST
                                           EndDate: ED
                                               num:max_get 
                                             start:0+i*max_get]; 
       
        if (pre_count==[google_data_array count]) {
            looprun=NO;
        }
        pre_count=[google_data_array count];
        
    }
   
    
    
    int index;
    index=0;
    
    NSMutableArray *out_array;
    out_array=[[[NSMutableArray alloc] init] autorelease];
    for (NSMutableDictionary *d in google_data_array) {
        
        NSArray * Times_array=[[d objectForKey:@"date"] componentsSeparatedByString:@","];        
        
        NSString *outs=nil;
        
        NSArray * MMM_array=[[Times_array objectAtIndex:0] componentsSeparatedByString:@" "]; 
       
        if ([MMM_array count]>1) {
            //NSLog(@"%i-%i-%i",[ self MMM_MonthConvertToInterger: [MMM_array objectAtIndex:0]],[[MMM_array objectAtIndex:1] intValue] ,[[Times_array objectAtIndex:1] intValue]   );
            
         
        
           outs=[ NSString stringWithFormat:@"%i-%i-%i,%0.2f,%0.2f,%0.2f,%0.2f,%i,%0.2f" ,[[Times_array objectAtIndex:1] intValue] , [ self MMM_MonthConvertToInterger: [MMM_array objectAtIndex:0]], [[MMM_array objectAtIndex:1] intValue]    , [[d objectForKey:@"open"] floatValue] , [[d objectForKey:@"high"] floatValue],[ [d objectForKey:@"low"] floatValue],[[d objectForKey:@"close"] floatValue] , [ [[d objectForKey:@"volume"] stringByReplacingOccurrencesOfString:@"," withString:@""] intValue] ,[[d objectForKey:@"close"] floatValue]  ];
        }
        
         
        
        [out_array addObject:outs];
        
        
        index=index+1;
    }
    
    
    //[google_data_array release];
    
    return  out_array;
       
}
//取出某一段時間 因為googl的日線資料僅可以取出200天 所以分段取出
-(NSMutableArray *)Google_HistoryData:(NSMutableArray *)google_data 
                               Symbol:(NSString *)symbol_s 
                            StartDate:(NSString *)StartDate_s 
                              EndDate:(NSString *)EndDate_s 
                                  num:(int)num_i 
                                start:(int) start_i {

    NSString *urls=[NSString stringWithFormat:@"http://www.google.com/finance/historical?q=%@&startdate=%@&enddate=%@&num=%i&start=%i",symbol_s,StartDate_s,EndDate_s,num_i,start_i] ;       
   
    NSLog(@"url=%@",urls);
    
    NSURL *  urla;
    urla = [NSURL URLWithString:urls];
    
    NSError * errorq = nil;
    NSString * download_string;
    download_string=[NSString stringWithContentsOfURL:urla encoding:NSASCIIStringEncoding error:&errorq];
    
    //NSLog(@"download_string=%@",download_string);
    
    NSError *error = nil;
    
    NSString *html;
    html=download_string;
    
    HTMLParser *rawparser = [[[HTMLParser alloc] initWithString:html error:&error] autorelease];
    
    if (error) {
        NSLog(@"Error: %@", error);
        return google_data;
    }
    
    HTMLNode *rawbodyNode = [rawparser body];
    
    //找出列  節點的開頭是tr
    NSArray *RawNodes = [rawbodyNode findChildTags:@"table"];
    int raw=1;
    for (HTMLNode *rawNode in RawNodes) {
        if ([[rawNode getAttributeNamed:@"class"] isEqualToString:@"gf-table historical_price"] ) {
            // NSLog(@"找到列的原始資料表格");
            //針對每個列 拆出行 column
            
            HTMLParser *columnparser = [[HTMLParser alloc] initWithString:[rawNode rawContents] error:&error];
            HTMLNode *columnbodyNode = [columnparser body];
            //找出行  節點的開頭是td           
            NSArray *ColumnNodes = [columnbodyNode findChildTags:@"td"]; 
            
            int column;
            
            NSMutableDictionary *tempa=nil;
            
            for (HTMLNode *rawNode_line in ColumnNodes) {
                //日期
                if ([[rawNode_line getAttributeNamed:@"class"] isEqualToString:@"lm"] )  {
                     
                    tempa=[[NSMutableDictionary alloc] init]; 
                    column=1;                      
                    
                    [tempa setObject:[rawNode_line contents] forKey:@"date"];
                    
                  //  NSLog(@"date=%@",[rawNode_line contents]);
                        
                    
                }   
                //報價
                if ([[rawNode_line getAttributeNamed:@"class"] isEqualToString:@"rgt"] )  {
                    
                    switch (column) {
                        case 1:{
                           // NSLog(@"open= %@" ,[rawNode_line contents]);
                            [tempa setObject:[rawNode_line contents] forKey:@"open"];                            
                            break;
                        }
                        case 2:{
                          //  NSLog(@"high= %@" ,[rawNode_line contents]);
                            [tempa setObject:[rawNode_line contents] forKey:@"high"];                            
                            break;
                        }  
                        case 3:{
                           // NSLog(@"low= %@" ,[rawNode_line contents]);
                              [tempa setObject:[rawNode_line contents] forKey:@"low"];                            
                            break;
                        }  
                        case 4:{
                           // NSLog(@"close= %@" ,[rawNode_line contents]);
                              [tempa setObject:[rawNode_line contents] forKey:@"close"];                            
                            
                            break;
                        }  
                            
                            
                            
                        default:
                            break;
                    }
                    
                    column=column+1;                     
                }    
                //成交量
                if ([[rawNode_line getAttributeNamed:@"class"] isEqualToString:@"rgt rm"] )  {
                  //  NSLog(@"volume=%@",[rawNode_line contents]);
                    [tempa setObject:[rawNode_line contents] forKey:@"volume"];                    
                    
                    [google_data addObject:tempa];
                    column=1;
                    [tempa release];
                    tempa=nil;
                    
                }                   
                
                
            }             
            
            
            
            
            [columnparser release];                 
            
            
            
            
            raw=raw+1;
        }
        
        else{
            //  NSLog(@"不是列的原始資料=%@", [rawNode rawContents]);             
            
        }
        
    }
    
   // [rawparser release];
    
    
    
    
    return google_data;
}




//Google資料 分時資料
-(void)Google_HistoryData_minutely{
    
    //利用 i=60 表示ㄧ60秒 與1d 下載一天資料來控制下載
    NSString *urls=@"http://www.google.com/finance/getprices?q=2498&x=TPE&i=60&p=1d&f=d,o,h,l,c,v" ;        
    
    
    NSURL *  urla;
    urla = [NSURL URLWithString:urls];
    
    NSError * errorq = nil;
    NSString * download_string;
    download_string=[NSString stringWithContentsOfURL:urla encoding:NSUTF8StringEncoding error:&errorq];
    NSLog(@"%@",download_string);
  
    //將資料分成列
    NSArray *csvLines ;	    
    csvLines = [download_string  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
    
    //int MARKET_OPEN_MINUTE;
    //int MARKET_CLOSE_MINUTE;
    int INTERVAL;
    //int TIMEZONE_OFFSET;
    int time_begin;    
    int time_begin_index;     
    //time_begin_index=-1;
    for (int i=0;i<[csvLines count];i++) {
        NSString *lines=[csvLines objectAtIndex:i] ;       
       // NSLog(@"%i %@",i,lines );
        if (i<7) {
        //前段資料基本的時間結構
          NSArray * line_array=[lines componentsSeparatedByString:@"="];            
            if ([line_array count]==2) {
                
                if ([[line_array objectAtIndex:0] isEqualToString:@"MARKET_OPEN_MINUTE"]) {
                   // MARKET_OPEN_MINUTE=[[line_array objectAtIndex:1] intValue];
                }
                else  if ([[line_array objectAtIndex:0] isEqualToString:@"MARKET_CLOSE_MINUTE"]) {
                    //MARKET_CLOSE_MINUTE=[[line_array objectAtIndex:1] intValue];
                }                
                else  if ([[line_array objectAtIndex:0] isEqualToString:@"INTERVAL"]) {
                    INTERVAL=[[line_array objectAtIndex:1] intValue];
                }                   
                else  if ([[line_array objectAtIndex:0] isEqualToString:@"TIMEZONE_OFFSET"]) {
                    //TIMEZONE_OFFSET=[[line_array objectAtIndex:1] intValue];
                }                 
            }
            
        }
        else{
            NSArray * line_array=[lines componentsSeparatedByString:@","];               
            if ([line_array count]==6) {  
                //開始取出資料
                //判讀第一筆交易 以便取出時間
                if ([lines hasPrefix:@"a"]) {
                    
                    
                    
                    //限制要有6個欄位資料
                    
                    time_begin=[[[line_array objectAtIndex:0] stringByReplacingOccurrencesOfString:@"a" withString:@""] intValue];
                    time_begin_index=0;                    
                  //  NSLog(@"time=%i",time_begin);
                    //轉換時間
                    NSDate *start_time ;
                    start_time=[NSDate dateWithTimeIntervalSince1970:time_begin+time_begin_index *INTERVAL  ];                 
                    NSDateFormatter *start_dateFormatter = [[NSDateFormatter alloc] init];
                    start_dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";  
                    NSString *string_start_time = [start_dateFormatter stringFromDate:start_time];  
                    NSLog(@"string_start_time=%@ %f",string_start_time,[[line_array objectAtIndex:1] floatValue]  );
                    [start_dateFormatter release];
                    
                    
                    
                    
                }
                else{
                    
                    time_begin_index=[ [line_array objectAtIndex:0] intValue];
                     
                    //轉換時間
                    NSDate *start_time ;
                    start_time=[NSDate dateWithTimeIntervalSince1970:time_begin+time_begin_index*INTERVAL   ];                 
                    NSDateFormatter *start_dateFormatter = [[NSDateFormatter alloc] init];
                    start_dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";  
                    NSString *string_start_time = [start_dateFormatter stringFromDate:start_time];  
                    NSLog(@"string_start_time=%@ %f",string_start_time ,[[line_array objectAtIndex:1] floatValue] );
                    [start_dateFormatter release];
                    
                    
                    
                    
                }
                
            
            
            
            }            
                       
        
        }
       // NSArray * line_array=[lines componentsSeparatedByString:@":"];
         
        
        
    }
    //NSLog(@"%i %i %i %i",MARKET_OPEN_MINUTE,MARKET_CLOSE_MINUTE,INTERVAL,TIMEZONE_OFFSET);
}

//撰寫評論啟動
-(void)AppRate{
    /*
     1.新增Appirater.h Appirater.m
     2.新增SystemConfiguration.framework
     3.網址 http://arashpayan.com/blog/2009/09/07/presenting-appirater/     
     */
    
    [Appirater appLaunched];
}

#pragma mark -
#pragma mark 以網頁HTTP url方式 POST資料

//標記:以網頁HTTP url方式 POST資料

-(void)record_login{
    //標記:程式啓動後 必須先決定的重要參數 7 先設定 預防失敗
    
    
       
   
    
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    
    NSString *BundleIdentifier;
    BundleIdentifier=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];     
   
    
    
    
    //取出device 資料
	UIDevice *device = [UIDevice currentDevice];
    
	NSString *device_uniqueIdentifier = [device uniqueIdentifier];    
    NSString *device_name = [device name];  
    NSString *device_systemName = [device systemName];
    NSString *device_systemVersion = [device systemVersion];  
    NSString *device_model = [device model];    
    NSString *device_localizedModel = [device localizedModel];     
    
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
    NSString *iap_type;
    iap_type= [prefs objectForKey:@"iap_type"];    
    
    
    //標記:POST 輸入變數 4  
    //另外php 為record_login.php
    
    NSURL *url = [NSURL URLWithString:@"http://www.xxtradexx.com/php_learn/record_login.php"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];    
    
    [request setPostValue:device_uniqueIdentifier forKey:@"udid"];
    [request setPostValue:device_name forKey:@"name"];
    [request setPostValue:device_systemName forKey:@"systemName"];    
    [request setPostValue:device_model forKey:@"model"];
    [request setPostValue:device_systemVersion forKey:@"systemVersion"];
    [request setPostValue:device_localizedModel forKey:@"localizedModel"];
    [request setPostValue:BundleIdentifier forKey:@"productid"];    
    [request setPostValue:DisplayName forKey:@"displayname"];  
    [request setPostValue:iap_type forKey:@"iap_type"];     

//標記:Add Target need Program  Preprocessor Macros 
//請務必要記住針對每個 Build Configuration提供
//作法：選定Tragets=>Build Settings=>Preprocessor Macros 針對不同的Configuration 給AppStore 或是Development    
     
#ifdef AppStore
     NSLog(@"On AppStore");
    [request setPostValue:[NSNumber numberWithInt: 1] forKey:@"debuger"]; 
#else
     NSLog(@"Not AppStore");
     
#endif    
#ifdef Development
     NSLog(@"On Development");
    [request setPostValue:[NSNumber numberWithInt: 2] forKey:@"debuger"];     
#else
     NSLog(@"Not Development"); 
    
#endif    
    
    
    /*注意
     目前尚未如果是在測試狀態下 不管是模擬機或是實體機上 都會是0
     但不確定如果 已經正式銷售的軟體會使 值變成1
     
     */
    [request setRequestMethod:@"POST"];
    
    [request setValidatesSecureCertificate:NO];
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(request_Finish:)];
    [request setDidFailSelector:@selector(request_Fail:)];    
    [request startAsynchronous];
    
    
    
    
    
}

-(void)request_Finish:(ASIHTTPRequest *)request{
    //標記:程式啓動後 必須先決定的重要參數 5 成功    
    NSString *response = [request responseString];
    NSLog(@"request_Finish:%@",response);    
    
    NSArray * Timestamp_array=[response componentsSeparatedByString:@":"];     
   
    if ([[Timestamp_array objectAtIndex:0] isEqualToString:@"ERROR"]  ) {
        //表示資料取出失敗
        NSLog(@"表示取出重要資料失敗");
    
    }
    else{
        //資料取出成功
        
        //將字串的每個elements 分解出來      
        NSMutableDictionary *jsonvalue_elements = [response JSONValue];
        
        //取出所有的資料
        p_datasource=[jsonvalue_elements objectForKey:@"datasource"];
        p_status=[jsonvalue_elements objectForKey:@"status"];
        p_user_grade=[jsonvalue_elements objectForKey:@"user_grade"];
        p_login_count=[jsonvalue_elements objectForKey:@"login_count"];    
        p_displayname=[jsonvalue_elements objectForKey:@"displayname"];
        p_firstentry_Date=[jsonvalue_elements objectForKey:@"firstentry_Date"];    
        p_iap_type=[jsonvalue_elements objectForKey:@"iap_type"];         
        p_expire_datetime_unix=[jsonvalue_elements objectForKey:@"expire_datetime_unix"];        
        
        //利用下面的城市可以列印出所有的值
        for (NSDictionary *s in jsonvalue_elements ) {
            NSLog(@"%@:%@",s,[jsonvalue_elements objectForKey:s]   );
        }            
        
        //標記:初始化重要參數值 從網路伺服器上取出
        if ([p_status isEqualToString:@"0"]) {
            //表示強迫不讓此程式執行
            NSLog(@"表示強迫不讓此程式執行");
            exit(0);            
        }
        else if ([p_status isEqualToString:@"1"]){
            //表示此程式可以執行
            NSLog(@"表示此程式可以執行");
        }
    
        if ([p_datasource isEqualToString:@"0"]) {
            //資料源:Yahoo
            NSLog(@"資料源:Yahoo");
            
            NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
            [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"isYahoo"];
            [prefs synchronize];		
        }
        else if ([p_datasource isEqualToString:@"1"]){
            //資料源:Google
            NSLog(@"資料源:Google");
            NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
            [prefs setObject:[NSNumber numberWithBool:NO]  forKey:@"isYahoo"];
            [prefs synchronize];	            
        }
        
        
        //可以開啓使用功能限制
        if ([p_user_grade isEqualToString:@"0"]) {
            //使用者等級分類:管理者
            NSLog(@"使用者等級分類:管理者");
            
            NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	            
            [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"isManager"];
			[prefs synchronize];            
            
        }
        else if ([p_user_grade isEqualToString:@"1"]){
            //使用者等級分類:非管理者
            NSLog(@"使用者等級分類:非管理者");
            
            NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	            
            [prefs setObject:[NSNumber numberWithBool:NO]  forKey:@"isManager"];
			[prefs synchronize]; 
            
        }
       
        if ([p_iap_type isEqualToString:@"Non-Consumable"]) {
            //網路購買商品的形態:一次購買買斷
            NSLog(@"網路購買商品的形態:一次購買買斷");
            
            //標記:購買方式 不是一次買斷就是訂閱方式         
            NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
           [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
           [prefs synchronize];		
                        
            /*如果一次購買 則第一次下載要付費
              並且有檔數的限制，也就是收兩種費用 所以僅有在編輯投資組合時檢查是否達到上限
             */
            
        }
        else if ([p_iap_type isEqualToString:@"Auto-Renewable Subscriptions"]){
            //使用者等級分類:非管理者
            NSLog(@"網路購買商品的形態:訂閱購買");
            NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
            [prefs setObject:@"Auto-Renewable Subscriptions" forKey:@"iap_type" ];
            [prefs synchronize];	
            
            /*如果訂閱購買 原則上是免費試用
              1.就取消每個投資組合最大檔數的限制
              2.第一次安裝時給的試用限制
              3.試用結束後 要讓選擇是否訂閱
              4.如果有開始訂閱 檢查訂閱是否到期
            */
            
        }
        
        //最後到期日
        NSDate* expireDate = [NSDate dateWithTimeIntervalSince1970:[ p_expire_datetime_unix intValue]  ];        
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        dateFormatter.dateFormat = @"yyyy-MMM-dd HH:mm:ss";
        
        NSString *timeStamp = [dateFormatter stringFromDate:expireDate];
        NSLog(@"到期日=%@",timeStamp);        
        [dateFormatter release];
        
    }
       
    
    
}

-(void)request_Fail:(ASIHTTPRequest *)request{
    //標記:程式啓動後 必須先決定的重要參數 6 失敗
}


#pragma mark -
#pragma mark UIApplicationDelegate-程式啟動執行
 /*
-(void)sc{
}
-(void)bc{
}
 */


//從 UIApplicationDelegate delegete 來的 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOption{    
    {
        /*
        //要加入 #import <sys/utsname.h>
        struct utsname systemInfo;
        uname(&systemInfo);
        NSLog(@"使用機型 型號=%@",[NSString stringWithCString:systemInfo.machine
                                       encoding:NSUTF8StringEncoding] );
        */
        
         
         /*
         if ([deviceString isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
         if ([deviceString isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
         if ([deviceString isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
         if ([deviceString isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
         if ([deviceString isEqualToString:@"iPhone3,2"])    return @"Verizon iPhone 4";
         if ([deviceString isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
         if ([deviceString isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
         if ([deviceString isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
         if ([deviceString isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
         if ([deviceString isEqualToString:@"iPad1,1"])      return @"iPad";
         if ([deviceString isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
         if ([deviceString isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
         if ([deviceString isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
         if ([deviceString isEqualToString:@"i386"])         return @"Simulator";
         if ([deviceString isEqualToString:@"x86_64"])       return @"Simulator";
         */
        
        
    }
   
    
    //基礎元件設計模組
    {
         //如何取出通訊錄名單 要加入AddressBook.framework 但是加入沒有用所以此段尚未完成
        /*
        {
            ABAddressBookRef addressBook = ABAddressBookCreate();
            
            CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);
            
            for(int i = 0; i < CFArrayGetCount(results); i++)
            {
                ABRecordRef person = CFArrayGetValueAtIndex(results, i);
                //读取firstname
                NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
                if(personName != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"\n姓名：%@\n",personName];
                //读取lastname
                NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
                if(lastname != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastname];
                //读取middlename
                NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);
                if(middlename != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlename];
                //读取prefix前缀
                NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);
                if(prefix != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",prefix];
                //读取suffix后缀
                NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);
                if(suffix != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",suffix];
                //读取nickname呢称
                NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);
                if(nickname != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",nickname];
                //读取firstname拼音音标
                NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);
                if(firstnamePhonetic != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",firstnamePhonetic];
                //读取lastname拼音音标
                NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);
                if(lastnamePhonetic != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastnamePhonetic];
                //读取middlename拼音音标
                NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);
                if(middlenamePhonetic != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlenamePhonetic];
                //读取organization公司
                NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);
                if(organization != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",organization];
                //读取jobtitle工作
                NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);
                if(jobtitle != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",jobtitle];
                //读取department部门
                NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);
                if(department != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",department];
                //读取birthday生日
                NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);
                if(birthday != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",birthday];
                //读取note备忘录
                NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);
                if(note != nil)
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",note];
                //第一次添加该条记录的时间
                NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);
                NSLog(@"第一次添加该条记录的时间%@\n",firstknow);
                //最后一次修改該条记录的时间
                NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);
                NSLog(@"最后一次修改該条记录的时间%@\n",lastknow);
                
                //获取email多值
                ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
                int emailcount = ABMultiValueGetCount(email);    
                for (int x = 0; x < emailcount; x++)
                {
                    //获取email Label
                    NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));
                    //获取email值
                    NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);
                    textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",emailLabel,emailContent];
                }
                //读取地址多值
                ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);
                int count = ABMultiValueGetCount(address);    
                
                for(int j = 0; j < count; j++)
                {
                    //获取地址Label
                    NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",addressLabel];
                    //获取該label下的地址6属性
                    NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);        
                    NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];
                    if(country != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"国家：%@\n",country];
                    NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];
                    if(city != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"城市：%@\n",city];
                    NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];
                    if(state != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"省：%@\n",state];
                    NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];
                    if(street != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"街道：%@\n",street];
                    NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];
                    if(zip != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"邮编：%@\n",zip];    
                    NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey];
                    if(coutntrycode != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"国家编号：%@\n",coutntrycode];    
                }
                
                //获取dates多值
                ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);
                int datescount = ABMultiValueGetCount(dates);    
                for (int y = 0; y < datescount; y++)
                {
                    //获取dates Label
                    NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));
                    //获取dates值
                    NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);
                    textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",datesLabel,datesContent];
                }
                //获取kind值
                CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);
                if (recordType == kABPersonKindOrganization) {
                    // it's a company
                    NSLog(@"it's a company\n");
                } else {
                    // it's a person, resource, or room
                    NSLog(@"it's a person, resource, or room\n");
                }
                
                
                //获取IM多值
                ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);
                for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++)
                {
                    //获取IM Label
                    NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);
                    textView.text = [textView.text stringByAppendingFormat:@"%@\n",instantMessageLabel];
                    //获取該label下的2属性
                    NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l);        
                    NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];
                    if(username != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"username：%@\n",username];
                    
                    NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];
                    if(service != nil)
                        textView.text = [textView.text stringByAppendingFormat:@"service：%@\n",service];            
                }
                
                //读取电话多值
                ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
                for (int k = 0; k<ABMultiValueGetCount(phone); k++)
                {
                    //获取电话Label
                    NSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));
                    //获取該Label下的电话值
                    NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k);
                    
                    textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",personPhoneLabel,personPhone];
                }
                
                //获取URL多值
                ABMultiValueRef url = ABRecordCopyValue(person, kABPersonURLProperty);
                for (int m = 0; m < ABMultiValueGetCount(url); m++)
                {
                    //获取电话Label
                    NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));
                    //获取該Label下的电话值
                    NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m);
                    
                    textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",urlLabel,urlContent];
                }
                
                //读取照片
                NSData *image = (NSData*)ABPersonCopyImageData(person);
                
                
                UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 0, 50, 50)];
                [myImage setImage:[UIImage imageWithData:image]];
                myImage.opaque = YES;
                [textView addSubview:myImage];
                
                
                
            }
            
            CFRelease(results);
            CFRelease(addressBook);        
        }
        */
        
        //時區模組 列出所有時區名稱
        //[self timezone_list_knownTimeZoneNames];     
        
        //時區模組    
         // [self timezone];
        
        //Yahoo代碼搜尋
        //[self Yahoo_code_search];     
        
        //Google資料 即時報價
         //[self Google_realtime]; 
        
        //Google資料 分時資料
        // [self Google_HistoryData_minutely];
        
        //Google資料 歷史資料 日線 週線
        /*
         NSMutableArray *out_aa= [self Google_HistoryData_Daily:@"3697&x=TPE" StartDates:@"2010-1-1" EndDates:@"2011-10-6"];
        
        //for (NSString *outs in out_aa ) {
            NSLog(@"%@",outs);
        }
          */
        //撰寫評論啟動
        // [self AppRate];
        
        //透過http模式 將資料post到網路伺服器上
         //[self php_post_data];        
    }
      
    
   // [[MKStoreManager sharedManager] purchasableObjectsDescription]  ;
       
    
    // tabBarController 可以使用
    tabBarController_isEnable=YES;    
    
    //iPad 開始
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        
        window = [[UIWindow alloc] initWithFrame:[[UIScreen  mainScreen] bounds]] ;
        
        [self Comm_iphone_ipad];
               
        //產生右邊次圖
        DetailViewController *detailView = [[DetailViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
         
        //分隔圖視窗物件
        Split_viewController = [[CustomUISplitViewController alloc] init];        
        //分隔圖的次視窗 
        
        Split_viewController.viewControllers = [NSArray arrayWithObjects: aTabBarController, detailView, nil];
        
        [detailView release];
        [aTabBarController release];
        
        Split_viewController.AppleDeglate=self;
              
        
        //左右視圖
        mv=aTabBarController;
        dv=detailView;
        
        //分隔視圖委派物件
        splitViewDelegate = [[SplitViewDelegate alloc] init];
        
        
        splitViewDelegate.detailController = detailView;
        splitViewDelegate.MasterController=aTabBarController;
        splitViewDelegate.AppleDeglate=self;
        
        Split_viewController.delegate = splitViewDelegate;
        [splitViewDelegate init_toolbar];      
        [splitViewDelegate init_popController]; 
        
        Master_popController=splitViewDelegate.popController;
        
        
        //不同作業系統版本的視窗選轉
         if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0){
            // warning: addSubView doesn't work on iOS6
            
           [window addSubview:Split_viewController.view];
        }
        else{
            
            
            // use this mehod on ios6
            [window setRootViewController:Split_viewController];
        }
    
        
        [window makeKeyAndVisible];
        
        //setting delegate to disable edit button in more.
        aTabBarController.moreNavigationController.delegate = self;        
        
         
        
        return YES;        
        
    
    }
    //iPhone 開始
    else{
        
        
        window = [[UIWindow alloc] initWithFrame:[[UIScreen  mainScreen] bounds]] ;
        
        [self Comm_iphone_ipad];
        
        //[window addSubview: aTabBarController.view ];	 與下面程式效果一樣
        [window addSubview: [aTabBarController view ]];		
         
        
        [window makeKeyAndVisible];
        return YES;         
       
           
       
    
    
    }
    
    
		
}


#pragma mark -
#pragma mark iPad 與iPhone通用啓動
-(void)Comm_iphone_ipad{
       
    //產生要儲存tab的檔案路徑與名稱
    {
        //版本
        NSString *version;
        version=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];	
        NSArray *copm=[version componentsSeparatedByString:@"."];	
        
        //名稱
       // filename=[[NSString alloc] initWithFormat: @"tab_%@_%@_%@.plistH " ,[copm objectAtIndex:0],[copm objectAtIndex:1],[[NSLocale preferredLanguages] objectAtIndex:0]];
        filename=[[NSString alloc] initWithFormat: @"tab_%@_%@_%@.plistH " ,[copm objectAtIndex:0],[copm objectAtIndex:1],@"temp"];
        
        //路徑
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString *dir = [paths objectAtIndex:0];
        //路徑+名稱
        filePath = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:filename]];
        [filename release];
        
    }
     
    
    aTabBarController = [[UITabBarController alloc] init];
    aTabBarController.delegate=self;
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    //檢查是否已經存有tab的檔案 
    //主要是要取出取出Tab的title  
    if ([fileManager fileExistsAtPath:filePath] == NO)
    {
        ArrayNavcontroller_title=[[NSMutableArray alloc] init];	
        
        NSString *DisplayName;
        DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; 
        
        //標記:Add Target need Program 
        //標記:Add New Market 
        if ([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_ETF"]) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"ETF",@"ETF") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	        
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];              
            
        } 
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_iStock Global"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
                       
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"IND",@"IND") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"US",@"US")  ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];               
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"UK",@"UK")  ];            
           // [ArrayNavcontroller_title addObject: NSLocalizedString(@"KS",@"KS") ];		
            
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"HK",@"HK") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CN",@"CN") ];            
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CH",@"CH") ];
           // [ArrayNavcontroller_title addObject: NSLocalizedString(@"TW",@"TW")  ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"SI",@"SI")  ];      
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"AX",@"AX") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"GR",@"GR")  ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"PA",@"PA")  ];               
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"MI",@"MI")  ];             
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"SA",@"SA")  ]; 
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"MX",@"MX")  ];                
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"INDIA",@"INDIA")  ];  
             [ArrayNavcontroller_title addObject: NSLocalizedString(@"NZ",@"NZ")  ];  
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
                      
            
        }
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_HK"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"HK",@"HK") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CH"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CH",@"CH") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_US"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"US",@"US") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		        
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_UK"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"UK",@"UK") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CN"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CN",@"CN") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		         
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_KS"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"KS",@"KS") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	  
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_iStock Global"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"IND",@"IND") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"US",@"US")  ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"HK",@"HK") ];  
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"UK",@"UK")  ];            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"KS",@"KS") ];		
           
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];             
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CN",@"CN") ];            
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CH",@"CH") ];
            //[ArrayNavcontroller_title addObject: NSLocalizedString(@"TW",@"TW")  ];
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"SI",@"SI") ];            
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"AX",@"AX") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"GR",@"GR")  ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"PA",@"PA")  ];            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"INDIA",@"INDIA")  ];  
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"NZ",@"NZ")  ];              
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"MI",@"MI")  ]; 
             [ArrayNavcontroller_title addObject: NSLocalizedString(@"SA",@"SA")  ];   
            
            
            
             [ArrayNavcontroller_title addObject: NSLocalizedString(@"MX",@"MX")  ];              
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];
            
            
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            
                       
        }
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_HK"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"HK",@"HK") ];
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
        }            
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SI"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"SI",@"SI") ];
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }                       
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CH"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CH",@"CH") ];
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }                  
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_AX"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"AX",@"AX") ];
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }   
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_GR"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"GR",@"GR") ];
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }   
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_PA"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"PA",@"PA") ];
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }   
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CN"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CN",@"CN") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		           
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_PA"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"PA",@"PA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		        
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_GR"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"GR",@"GR") ];
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
             [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }   
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_AX"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"AX",@"AX") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_UK"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"UK",@"UK") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		           
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_ETF"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"ETF",@"ETF") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SI"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"SI",@"SI") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		        
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_US"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"US",@"US") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		        //注意如果要修改title 內容 務必要修改 紀錄檔案名稱 例如 tab.plist		
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_INDIA"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"INDIA",@"INDIA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }		        
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_INDIA"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"INDIA",@"INDIA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_NZ"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"NZ",@"NZ") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	        
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_NZ"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"NZ",@"NZ") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MI"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"MI",@"MI") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	        
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MI"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"MI",@"MI") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	              
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SA"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
           // [ArrayNavcontroller_title addObject: NSLocalizedString(@"SA",@"SA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }       
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SA"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            // [ArrayNavcontroller_title addObject: NSLocalizedString(@"SA",@"SA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }   
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MX"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            // [ArrayNavcontroller_title addObject: NSLocalizedString(@"SA",@"SA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }             
        else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MX"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            // [ArrayNavcontroller_title addObject: NSLocalizedString(@"SA",@"SA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }  
        else if([DisplayName isEqualToString:@"2D_BASIC_MESA_iPhone_Global"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            //標記:增加Treemap 至 viewcontroller 測試開起關閉位置           
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"Treemap",@"Treemap") ];            
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"IND",@"IND") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"US",@"US")  ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];               
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"UK",@"UK")  ];            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"KS",@"KS") ];		
            
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"HK",@"HK") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CN",@"CN") ];            
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CH",@"CH") ];
             [ArrayNavcontroller_title addObject: NSLocalizedString(@"TW",@"TW")  ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"SI",@"SI")  ];      
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"AX",@"AX") ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"GR",@"GR")  ];
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"PA",@"PA")  ];               
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"MI",@"MI")  ];             
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"SA",@"SA")  ]; 
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"MX",@"MX")  ];                
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"INDIA",@"INDIA")  ];  
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"NZ",@"NZ")  ];  
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            
            
        }
        else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_AX"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"AX",@"AX") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	        
        else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_UK"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"UK",@"UK") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	    
        else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_US"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"US",@"US") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	           
        else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_HK"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"HK",@"HK") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	
        else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_CH"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"CH",@"CH") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }
        else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_INDIA"]  ) {
            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")];	
            
            [ArrayNavcontroller_title addObject: NSLocalizedString(@"INDIA",@"INDIA") ];
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"SETUP",@"SETUP")];	
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Upgrade",@"Upgrade")];	            
            [ArrayNavcontroller_title addObject:NSLocalizedString(@"Help",@"Help")];            
            
        }	            
    } // end if
    else{
        NSLog(@"取出ＴＡＢ資料");
       
        NSMutableArray *temp;
        temp=[[NSMutableArray alloc] initWithContentsOfFile:filePath]     ;
        
        ArrayNavcontroller_title=temp ;
        //[temp release];
    }  
    
    
    //初始化參數    
    [self init_para];
     
    //從伺服器取出是否要改變重要參數
    [self record_login];     
    
    //初始化Tab
    [self init_tab];
    
}

#pragma mark -
#pragma mark 初始參數

-(void)init_para{
    //初始化參數
	{
		NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];			
		
        //標記:初始化重要參數值 第一次安裝的初始化        
        {
            //是否為管理者
            //標記:isManager         
            if ([prefs  objectForKey:@"isManager"]==nil) {
                [prefs setObject:[NSNumber numberWithBool:NO]  forKey:@"isManager"];
                [prefs synchronize];		
            }	
	        
            //資料來源 如果不是雅虎就是google
            //標記:資料來源 isYagoo         
            if ([prefs  objectForKey:@"isYahoo"]==nil) {
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"isYahoo"];
                [prefs synchronize];		
            }            
             
                 
            
            
        }
        
       	
		
        
        /*
        //針對可以使用google資料的區域自動轉成google資料
        {
            NSString *DisplayName;
            DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];   
            
            
            NSArray * DisplayName_array=[DisplayName componentsSeparatedByString:@"_"];          
            if ([DisplayName_array count]==5) {
                //目前僅有中國 港股 美國 與ＥＴＦ強迫採用google 資料來試試看 其他資料還是以Yahoo資料為主
                if ([[DisplayName_array objectAtIndex:4] isEqualToString:@"HK"] || [[DisplayName_array objectAtIndex:4] isEqualToString:@"CH"] || [[DisplayName_array objectAtIndex:4] isEqualToString:@"US"] || [[DisplayName_array objectAtIndex:4] isEqualToString:@"ETF"]   ) {
                     [prefs setObject:[NSNumber numberWithBool:NO]  forKey:@"isYahoo"];                    
                }
                else{
                    [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"isYahoo"];                  
                }
            }
            
           
           
        }
        */
        
        
        //標記:是否顯示日內線圖的選擇區域         
		if ([prefs  objectForKey:@"isShowIntradayGraphSelected"]==nil) {
			[prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"isShowIntradayGraphSelected"];
			[prefs synchronize];		
		}		        
        
        
        //標記:升級功能限制 是否顯示技術指標上的買賣訊號
        /* 
        //標記:是否顯示技術指標上的買賣訊號         
		if ([prefs  objectForKey:@"isShowBuySellSignal"]==nil) {
			[prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"isShowBuySellSignal"];
			[prefs synchronize];		
		}
         */
         
         
        //是否為要進行最佳化 如果選no 則最佳化後的商品代碼不會被刪除
		if ([prefs  objectForKey:@"isActiveOptimize"]==nil) {
			[prefs setObject:[NSNumber numberWithBool: YES]  forKey:@"isActiveOptimize"];
			[prefs synchronize];		
		}
		//標記:是否移除交易所碼
		if ([prefs  objectForKey:@"isRemoveExchangeCode"]==nil) {
			[prefs setObject:[NSNumber numberWithBool: YES]  forKey:@"isRemoveExchangeCode"];
			[prefs synchronize];		
		}        
        
        //InAppPurchast 限制在自選股內可以使用的檔數限制		
		if ([prefs  objectForKey:@"MaxSymbolsWatchlist"]==nil) {
			
            
            NSString *DisplayName;
            DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; 
           
            //標記:Add Target need Program            
            if ([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_ETF"]) {
                [prefs setObject:[NSNumber numberWithInteger:10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
                
                
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_iStock Global"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_HK"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CH"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_US"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_UK"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CN"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_KS"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }     
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_iStock Global"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_HK"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SI"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CH"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_AX"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_GR"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                       
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_PA"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                       
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CN"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger:10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_PA"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_GR"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_AX"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_UK"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }           
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_ETF"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SI"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_US"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_INDIA"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_INDIA"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }      
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_NZ"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_NZ"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MI"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MI"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SA"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SA"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MX"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MX"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_MESA_iPhone_Global"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 40] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }             
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_AX"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }      
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_UK"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }  
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_US"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                 
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_HK"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }            
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_CH"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }   
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_INDIA"]  ) {
                
                [prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"MaxSymbolsWatchlist" ];
                [prefs synchronize];	
            }                 
            
            
        }			
		//標記:訂閱方式初始化
        if ([prefs  objectForKey:@"iap_type"]==nil) {
			
            
            NSString *DisplayName;
            DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; 
            
            //標記:Add Target need Program            
            if ([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_ETF"]) {
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
                
                
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_iStock Global"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_HK"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CH"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_US"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }                
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_UK"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CN"]  ) {
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }                  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_KS"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }     
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_iStock Global"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_HK"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SI"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CH"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_AX"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_GR"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }                       
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_PA"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }                       
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CN"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_PA"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }                 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_GR"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_AX"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_UK"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }           
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_ETF"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SI"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }                    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_US"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_INDIA"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }                   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_INDIA"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }      
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_NZ"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }                
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_NZ"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MI"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MI"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SA"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SA"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	

            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MX"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MX"]  ) {
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_MESA_iPhone_Global"]  ) {
                
                [prefs setObject:@"Auto-Renewable Subscriptions" forKey:@"iap_type" ];
                [prefs synchronize];	

            }             
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_AX"]  ) {
                              
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
	
            } 
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_UK"]  ) {
              
               	  
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
                
            } 
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_US"]  ) {
                
                
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
                
            }                      
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_HK"]  ) {
                
                
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
                
            }                 
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_CH"]  ) {
                
                
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
                
            }                 
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_INDIA"]  ) {
                
                
                
                [prefs setObject:@"Non-Consumable" forKey:@"iap_type" ];
                [prefs synchronize];	
                
            }       
        }			
        // 
     
        //標記:功能限定初始化
        
        if (YES) {
			
            
            NSString *DisplayName;
            DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; 
            
            //標記:Add Target need Program            
            if ([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_ETF"]) {
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
                
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_iStock Global"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_HK"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"];                 [prefs synchronize];	
                
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CH"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_US"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_UK"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CN"]  ) {
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"];                [prefs synchronize];	
                
            }                  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_KS"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }     
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_iStock Global"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_HK"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SI"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CH"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_AX"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_GR"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                       
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_PA"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                       
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CN"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_PA"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_GR"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_AX"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_UK"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }           
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_ETF"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SI"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_US"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_INDIA"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                   
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_INDIA"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }      
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_NZ"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_NZ"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }    
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MI"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MI"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SA"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"];                 [prefs synchronize];	
                
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SA"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MX"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }              
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MX"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }  
            else if([DisplayName isEqualToString:@"2D_BASIC_MESA_iPhone_Global"]  ) {
                
               [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }             
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_AX"]  ) {
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            } 
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_UK"]  ) {
                
                
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }               
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_US"]  ) {
                
                
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }            
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_HK"]  ) {
                
                
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }              
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_CH"]  ) {
                
                
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                  
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_INDIA"]  ) {
                
                
                
                [prefs setObject:[NSNumber numberWithBool:YES]  forKey:@"CanDragToRefreshQuoteTable"]; 
                [prefs synchronize];	
                
            }                   
        }        
		//報價 的欄位初始化
		{
			//第一欄
			if ([prefs  objectForKey:@"tableR0"]==nil) {
				[prefs setObject:[NSNumber numberWithInteger: 4] forKey:@"tableR0" ];
				[prefs synchronize];	
			}	
			if ([prefs  objectForKey:@"tableR1"]==nil) {
				[prefs setObject:[NSNumber numberWithInteger: 4] forKey:@"tableR1" ];
				[prefs synchronize];	
			}
			if ([prefs  objectForKey:@"tableR2"]==nil) {
				[prefs setObject:[NSNumber numberWithInteger: 8] forKey:@"tableR2" ];
				[prefs synchronize];	
			}				
			
		}
		//是否在左邊圖上顯式數值資料
		if ([prefs  objectForKey:@"isSowIndicatorNumber"]==nil) {
			
			[prefs setObject:[NSNumber numberWithBool: YES]  forKey:@"isSowIndicatorNumber"];
			[prefs synchronize];		
		}
		//技術指標使用與參數設定
		{
			
			//是否 移動均線	
			{
				if ([prefs  objectForKey:@"isMVindicator1"]==nil) {
					[prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMVindicator1"];
					[prefs synchronize];		
				}	
				if ([prefs  objectForKey:@"isMVindicator2"]==nil) {
					[prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMVindicator2"];
					[prefs synchronize];		
				}		
				if ([prefs  objectForKey:@"isMVindicator3"]==nil) {
					[prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMVindicator3"];
					[prefs synchronize];		
				}	
				if ([prefs  objectForKey:@"isMVindicator4"]==nil) {
					[prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMVindicator4"];
					[prefs synchronize];		
				}	
				if ([prefs  objectForKey:@"isMVindicator5"]==nil) {
					[prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMVindicator5"];
					[prefs synchronize];		
				}				
				
			}
			//移動均線參數設定
			{
				
				if ([prefs objectForKey:@"number_MVindicator1"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 5] forKey:@"number_MVindicator1"];
					[prefs synchronize];	
				}
				if ([prefs objectForKey:@"number_MVindicator2"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 10] forKey:@"number_MVindicator2"];
					[prefs synchronize];	
				}
				if ([prefs objectForKey:@"number_MVindicator3"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 20] forKey:@"number_MVindicator3"];
					[prefs synchronize];
				}	
				if ([prefs objectForKey:@"number_MVindicator4"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 60] forKey:@"number_MVindicator4"];
					[prefs synchronize];	
				}		
				if ([prefs objectForKey:@"number_MVindicator5"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 120] forKey:@"number_MVindicator5"];
					[prefs synchronize];	
				}
				
			}
			//是否KD	
			if ([prefs  objectForKey:@"isKDindicator"]==nil) {
				[prefs setObject:[NSNumber numberWithBool: YES]  forKey:@"isKDindicator"];
				[prefs synchronize];		
			}		
			//KD參數設定
			{
				
				if ([prefs objectForKey:@"number_KD_N"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 9] forKey:@"number_KD_N"];
					[prefs synchronize];	
				}
				if ([prefs objectForKey:@"number_KD_M1"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 3] forKey:@"number_KD_M1"];
					[prefs synchronize];	
				}
				if ([prefs objectForKey:@"number_KD_M2"]==nil) {
					[prefs setObject:[NSNumber numberWithInteger: 3] forKey:@"number_KD_M2"];
					[prefs synchronize];
				}			
			}
			//是否volume	
			if ([prefs  objectForKey:@"isVolumeindicator"]==nil) {
				[prefs setObject:[NSNumber numberWithBool: YES]  forKey:@"isVolumeindicator"];
				[prefs synchronize];		
			}			
			
            //標記:判斷是MESA或LF
            NSString *DisplayName;
            DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
            NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
            
            if ([DisplayName_array count]>=3) {
                if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
                    //MESA
                    //否LF
                    {
                        
                        
                        if ([prefs  objectForKey:@"isLF1"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isLF1"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isLF2"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isLF2"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isLF3"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isLF3"];
                            [prefs synchronize];		
                        }	
                    }
                    //是MESA
                    {
                        if ([prefs  objectForKey:@"isMESA1"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: YES]  forKey:@"isMESA1"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isMESA2"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMESA2"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isMESA3"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMESA3"];
                            [prefs synchronize];		
                        }			
                        
                    }
                    
                    
                    
                    
                }
                else{
                    //開始LF
                    //是LF
                    {
                        
                        
                        if ([prefs  objectForKey:@"isLF1"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: YES]  forKey:@"isLF1"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isLF2"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isLF2"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isLF3"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isLF3"];
                            [prefs synchronize];		
                        }	
                    }
                    //否MESA
                    {
                        if ([prefs  objectForKey:@"isMESA1"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMESA1"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isMESA2"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMESA2"];
                            [prefs synchronize];		
                        }			
                        
                        if ([prefs  objectForKey:@"isMESA3"]==nil) {
                            [prefs setObject:[NSNumber numberWithBool: NO]  forKey:@"isMESA3"];
                            [prefs synchronize];		
                        }			
                        
                    }
                    
                    
                    
                    
                }
            }
                        
            
            
        
			
		}
		//最佳化設定初始化	
		{
			
			if ([prefs objectForKey:@"OptimizeTradeSystem"]==nil) {
				[prefs setObject:@"MESA" forKey:@"OptimizeTradeSystem"];
				[prefs synchronize];	 		
			}
			//策略內部	
			if ([prefs objectForKey:@"tradeindex"]==nil) {
				[prefs setObject:@"1" forKey:@"tradeindex"];
				[prefs synchronize];	 		
			}
			//停損出場率(%)	
			if ([prefs objectForKey:@"Optimizestopratearay"]==nil) {
				
				[prefs setObject:@"0.15" forKey:@"Optimizestopratearay"];
				[prefs synchronize];	 		
			}
			//買賣手續費率(%)
			if ([prefs objectForKey:@"Optimizescostfeeratearay"]==nil) {
				
				[prefs setObject:@"0.002" forKey:@"Optimizescostfeeratearay"];
				[prefs synchronize];	//將記憶體中的資料存到硬體上 儲存指令		
			}
			//買賣或是兩者都有的交易	
			if ([prefs objectForKey:@"buysellboth"]==nil) {
				
				[prefs setObject:@"僅作多" forKey:@"buysellboth"];
				[prefs synchronize];	 		
			}
			//進出場時間選擇	
			if ([prefs objectForKey:@"enterTime"]==nil) {
				
				[prefs setObject:@"當日" forKey:@"enterTime"];
				[prefs synchronize];	 		
			}
			//進出場價格選擇	
			if ([prefs objectForKey:@"enterprice"]==nil) {
				
				[prefs setObject:@"開盤價" forKey:@"enterprice"];
				[prefs synchronize];	 		
			}
			//進出場數量選擇	
			if ([prefs objectForKey:@"enternumber"]==nil) {
				
				[prefs setObject:@"金額:5萬" forKey:@"enternumber"];
				[prefs synchronize];	 		
			}
			
			
		}
		//設定初始化
		{
			//k線起始日
			if ([prefs objectForKey:@"startUseDate"]==nil) {
				//設定全部時間
				NSTimeInterval secondsAgo = -timeIntervalForNumberOfWeeks(104); //預設3年期資料開始
				NSDate *aStartDate = [NSDate dateWithTimeIntervalSinceNow:secondsAgo]; 
				
				NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
				[prefs setObject:aStartDate forKey:@"startUseDate"];
				[prefs synchronize];			
				
			}
			//使用還權
			if ([prefs  objectForKey:@"isUseAfterStockSplit"] ==nil) {
				//搜尋是否要使用名稱
				[prefs setObject:@"Y" forKey:@"isUseAfterStockSplit"];
				[prefs synchronize];	//將記憶體中的資料存到硬體上 儲存指令 			 
			}
			//使用備份網路伺服器
			if ([prefs  objectForKey:@"isUseBackUPdatabase"] ==nil) {
				//搜尋是否要使用名稱
				[prefs setObject:@"N" forKey:@"isUseBackUPdatabase"];
				[prefs synchronize];	//將記憶體中的資料存到硬體上 儲存指令 			 
			}			
		}
		//搜尋國家的初始
        {
            if ( ![prefs objectForKey:@"Search Country"]) {
                //加入可搜懸的國家
                NSMutableArray *country;
                country=[[NSMutableArray alloc] init];
                
                
                NSString *DisplayName;
                DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; 
                
                //標記:Add Target need Program                
                if ([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_ETF"]) {
                    
                    [country addObject:@"ETF"];
                    
                    
                } 
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_iStock Global"]  ) {
                    [country addObject:@"US"];
                    [country addObject:@"HK"];   
                    [country addObject:@"CH"];                      
                    
                }  
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_HK"]  ) {
                    [country addObject:@"HK"];   
                                 
                    
                }                 
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CH"]  ) {
                    [country addObject:@"CH"];   
                    
                    
                }    
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_US"]  ) {
                    [country addObject:@"US"];   
                    
                    
                }                     
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_UK"]  ) {
                    [country addObject:@"UK"];   
                    
                    
                }   
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CN"]  ) {
                    [country addObject:@"CN"];   
                    
                    
                }                   
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_KS"]  ) {
                    [country addObject:@"KS"];   
                    
                    
                }    
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_iStock Global"]  ) {
                    [country addObject:@"US"];
                    [country addObject:@"HK"];   
                    [country addObject:@"CH"];                      
                    
                }                  
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_HK"]  ) {
                    [country addObject:@"HK"];   
                                 
                    
                }                      
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SI"]  ) {
                    [country addObject:@"SI"];   
                    
                    
                }                      
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CH"]  ) {
                    [country addObject:@"CH"];   
                    
                    
                }                       
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_AX"]  ) {
                    [country addObject:@"AX"];   
                    
                    
                }                         
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_GR"]  ) {
                    [country addObject:@"GR"];   
                    
                    
                }  
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_PA"]  ) {
                    [country addObject:@"PA"];   
                    
                    
                }                        
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CN"]  ) {
                    [country addObject:@"CN"];   
                    
                    
                }                     
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_PA"]  ) {
                    [country addObject:@"PA"];   
                    
                    
                }   
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_GR"]  ) {
                    [country addObject:@"GR"];   
                    
                    
                }  
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_AX"]  ) {
                    [country addObject:@"AX"];   
                    
                    
                }   
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_UK"]  ) {
                    [country addObject:@"UK"];   
                    
                    
                }                  
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_ETF"]  ) {
                    [country addObject:@"ETF"];   
                    
                    
                }           
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SI"]  ) {
                    [country addObject:@"SI"];   
                    
                    
                }                       
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_US"]  ) {
                    [country addObject:@"US"];   
                    
                    
                }        
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_INDIA"]  ) {
                    [country addObject:@"INDIA"];   
                    
                    
                }                   
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_INDIA"]  ) {
                    [country addObject:@"INDIA"];   
                    
                    
                }  
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_NZ"]  ) {
                    [country addObject:@"NZ"];   
                    
                    
                }                     
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_NZ"]  ) {
                    [country addObject:@"NZ"];   
                    
                    
                }                      
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MI"]  ) {
                    [country addObject:@"MI"];   
                    
                    
                }                
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MI"]  ) {
                    [country addObject:@"MI"];   
                    
                    
                }                          
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SA"]  ) {
                    [country addObject:@"SA"];   
                    
                    
                }
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SA"]  ) {
                    [country addObject:@"SA"];   
                    
                    
                }
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MX"]  ) {
                    [country addObject:@"MX"];   
                    
                    
                }                
                else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MX"]  ) {
                    [country addObject:@"MX"];   
                    
                    
                }                   
                else if([DisplayName isEqualToString:@"2D_BASIC_MESA_iPhone_Global"]  ) {
                    [country addObject:@"US"];
                    [country addObject:@"HK"];   
                    [country addObject:@"CH"];                      
                    
                }                        
                else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_AX"]  ) {
                    [country addObject:@"AX"];   
                    
                    
                }                   
                else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_UK"]  ) {
                    [country addObject:@"UK"];   
                    
                    
                }                       
                else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_US"]  ) {
                    [country addObject:@"US"];   
                    
                    
                }  
                else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_HK"]  ) {
                    [country addObject:@"HK"];   
                    
                    
                }                  
                else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_CH"]  ) {
                    [country addObject:@"CH"];   
                    
                    
                }    
                else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_INDIA"]  ) {
                    [country addObject:@"INDIA"];   
                    
                    
                }                    
                
                
                
                [prefs setObject:country  forKey:@"Search Country"];
                [country release];
                [prefs synchronize];	//將記憶體中的資料存到硬體上 儲存指令
                
                
                
            }	        
        }
        //上漲下跌顏色
        {
            //上漲顏色	
			if ([prefs objectForKey:@"upColor"]==nil) {
				
				[prefs setObject:@"greenColor"  forKey:@"upColor"];
				[prefs synchronize];	 		
			}        
            //下跌顏色	
			if ([prefs objectForKey:@"downColor"]==nil) {
				
				[prefs setObject:@"redColor" forKey:@"downColor"];
				[prefs synchronize];	 		
			}                   
            
            
        
        }
        
        
        
		
	}

}

#pragma mark -
#pragma mark Tab 初始與改變

-(void)init_tab{
    	
	 
	 	
	
	
		
	ArrayNavcontroller_object=[[NSMutableArray alloc] init];
	 
	
	int seltab;
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
         seltab=7 ;                
        
    }
    else
    {
         seltab=4;                
        
    }
    
    
    
    
    
    
	for (int i=0; i<[ArrayNavcontroller_title count]; i++) {
		
		//Tab  名稱
		NSString *title;
		title=[ArrayNavcontroller_title	 objectAtIndex:i];
		
		if ([title isEqualToString:NSLocalizedString(@"SETUP",@"SETUP") ]) {
			
			Setup *ST;
			ST=[[Setup alloc] init];
			[ST autorelease];
			[ST initTitle:title];
			[ST initImage:[UIImage imageNamed:@"toolbox.png"]];
			
			navcontroller *navc;
			navc=[[navcontroller alloc] initWithRootViewController:ST];		
			 
			if (i < seltab) {
				[ST get_navcontroller:navc];				
			}
			else {
				[ST get_navcontroller:aTabBarController.moreNavigationController];				
			}
            
            			
			[ArrayNavcontroller_object addObject:navc];		
			[navc release];
            
			
		}
        else if ([title isEqualToString:NSLocalizedString(@"Help",@"Help") ]) {
			
			HelpViewController *he;
			he=[[HelpViewController alloc] init];
			[he autorelease];
			 [he initTitle:title];
			 [he initImage:[UIImage imageNamed:@"Help.png"]];
			he.AppleDeglate=self;
            self.ahelp=he;
            
			navcontroller *navc;
			navc=[[navcontroller alloc] initWithRootViewController:he];		
            
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
                if (i < seltab) {
                    [he get_navcontroller:navc];				
                }
                else {
                    [he get_navcontroller:aTabBarController.moreNavigationController];				
                }            
            }
            else{
                if (i <= seltab) {
                    [he get_navcontroller:navc];				
                }
                else {
                    [he get_navcontroller:aTabBarController.moreNavigationController];				
                }            
            }
            
			
            
           // [he get_navcontroller:navc];
            
			[ArrayNavcontroller_object addObject:navc];		
			[navc release];
			
		}        
		else if([title isEqualToString:NSLocalizedString(@"Upgrade",@"Upgrade") ]){
			
			InAppPurchase *ST;
			ST=[[InAppPurchase alloc] init];
			[ST autorelease];
			[ST initTitle:title];
			[ST initImage:[UIImage imageNamed:@"lock.png"]];
			
			navcontroller *navc;
			navc=[[navcontroller alloc] initWithRootViewController:ST];		
			 
			if (i < seltab) {
				[ST get_navcontroller:navc];				
			}
			else {
				[ST get_navcontroller:aTabBarController.moreNavigationController];				
			}	
			
			// pre_tablecontroller=navc;  
            [ArrayNavcontroller_object addObject:navc];			
		    [navc release];
		}
        else if([title isEqualToString:NSLocalizedString(@"Treemap",@"Treemap") ]){
			
			TreeMapViewController *ST;
			ST=[[TreeMapViewController alloc] init];
			[ST autorelease];
			[ST initTitle:title];
			[ST initImage:[UIImage imageNamed:@"lock.png"]];
			
			navcontroller *navc;
			navc=[[navcontroller alloc] initWithRootViewController:ST];		
            
			if (i < seltab) {
				[ST get_navcontroller:navc];				
			}
			else {
				[ST get_navcontroller:aTabBarController.moreNavigationController];				
			}	
			
			// pre_tablecontroller=navc;  
            [ArrayNavcontroller_object addObject:navc];			
		    [navc release];
		}        
        else {
			
            //表單
            StockTableController *ST;
			ST=[[StockTableController alloc] initWithStyle:UITableViewStyleGrouped];
			 
			[ST initTitle:title];
            [ST initImage:[UIImage imageNamed:[title stringByAppendingString:@".png" ]]];
			ST.AppleDeglate=self;
            //導覽列
			navcontroller *navc;
			navc=[[navcontroller alloc] initWithRootViewController:ST];	
            navc.delegate=self;
            [ST release];
			 
            
            
            if (i < seltab) {
				[ST get_navcontroller:navc];
				
			}
			else {
				[ST get_navcontroller:aTabBarController.moreNavigationController];				
			}
           
            
            if (pre_tablecontroller==nil) {
                //這樣會指定 第一個取到的指標是自選股 
                 pre_tablecontroller=navc; 
            }
            
            
            
            [ArrayNavcontroller_object addObject:navc];
             [navc release];
            
		}
		
		
	}
	
    //[aTabBarController setViewControllers:ArrayNavcontroller_object]; 與下面程式效果一樣 
    aTabBarController.viewControllers=ArrayNavcontroller_object;	 
	[ArrayNavcontroller_object release];	
	 
	
}
 
#pragma mark -
#pragma mark 取的走勢圖設定上的popController參考位置

-(void)Get_popController_info:(UIPopoverController *)get_popController_info{
     NSLog(@"-(void)Get_popController_info:(UIPopoverController *)get_popController_info");    
    popController_info=get_popController_info;
}
-(void)Get_popController_info_next:(UIPopoverController *)get_popController_info_next{
    NSLog(@"-(void)Get_popController_info_next:(UIPopoverController *)get_popController_info_next");
    popController_info_next=get_popController_info_next;
}

#pragma mark -
#pragma mark 當retaincount=0 時 記憶體釋放前先清除之前的物件

- (void)dealloc {
	
    [aTabBarController  release];
	
    [interfaceOrientation_ipad release];
    [agraph release];    
     
	[filePath release]; // Tab 檔案名稱與路徑
	[filename release];	// Tab 檔案名稱
	
	 
	[ArrayNavcontroller_title release];	
     
    [Split_viewController release];	
       
    [splitViewDelegate release];    
    
    [mv release];
    [dv release];    
         
    [window release];
    [super dealloc];
}

#pragma mark -
#pragma mark 取的裝置目前的方向

-(void)Get_interfaceOrientation:(NSString *)Orientation{
    interfaceOrientation_ipad=Orientation;
   
    
}
#pragma mark -
#pragma mark 取的繪圖的參考

-(void)Get_agraph:(StockGrapth *)astockgraph{
    agraph=astockgraph;
}
//標記:navigationController 委託事件 往回推的時候,會把前面的ViewController  Release
#pragma mark -
#pragma mark navigationController 委託事件
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
   
    
    NSLog(@"完成didShowViewController:[%@]", [viewController class]);
    NSLog(@"完成navigationController:[%@]", [navigationController class]);    
    if ([viewController isKindOfClass:NSClassFromString(@"UIMoreListController")]) {
        UINavigationBar *morenavbar = navigationController.navigationBar;
        UINavigationItem *morenavitem = morenavbar.topItem;
        morenavitem.rightBarButtonItem = nil;    
    }
    
    
      
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
   
    NSLog(@"將要willShowViewController:[%@]", [viewController class]);
   
    
    if (viewController!=nil) {
       // if ([pre_navigationController isKindOfClass:[StockTableQuote class]]) {
          //  NSLog(@"消除StockTableQuote 記憶體-開始");
           // [pre_tablecontroller release];
       // }
        NSLog(@"消除StockTableQuote 記憶體-結束");
       // if (viewController!=nil) {
          //  NSLog(@"pre_navigationController=viewController-開始");
            
          //  pre_navigationController=viewController;
          //  NSLog(@"pre_navigationController=viewController-結束");
       // }
        
        
        
    }    
    

}






#pragma mark -
#pragma mark UITabBarControllerDelegate-委託事件與暫停使用

//標記:tabBarController 暫停使用 設定開啓與關閉值

-(void)Set_tabBarController_Enable{
    tabBarController_isEnable=YES;
    NSLog(@"tabBarController_isEnable 開啓使用");
}
-(void)Set_tabBarController_DisEnable{
    tabBarController_isEnable=NO;
    NSLog(@"tabBarController_DisEnable 關閉使用");
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0){
    return  tabBarController_isEnable;
    
}


//標記:tabBarController 委託事件 切換的時候不會把前面的ViewController  Release

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    /*注意
     viewController的類別是 navcontroller
     而StockTableController, Setup,  InAppPurchase 是加入至  navcontroller 裡
     
     */
    
    
    if (pre_tablecontroller!=nil && [[(navcontroller *)pre_tablecontroller viewControllers] count]>0   ) {
        //將畫面推到最前面 否則會產生Crash
        [(navcontroller *)pre_tablecontroller popToRootViewControllerAnimated:YES]  ;        
        
        //針對第一各畫面清除記憶體資料
        
        if (  [[[(navcontroller *)pre_tablecontroller viewControllers] objectAtIndex:0] isKindOfClass:[StockTableController class ]])  {
            //如果選定的類別是 StockTableController 則清除記憶 主要是因為有可能選到設定或是升級的類別
            can_use_graph_setup=@"NO";
            [(StockTableController *)[[(navcontroller *)pre_tablecontroller viewControllers] objectAtIndex:0]   Realese_Menory];        
            
            
        }
    }
    //已經執行清除記憶體之後,將目前的類別設定為前一類別
    pre_tablecontroller= (navcontroller *)viewController  ;
}
//UITabBarControllerDelegate 產生的
- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
	if (changed) {
		NSLog (@"User has rearranged tab bar items");
        [ArrayNavcontroller_title removeAllObjects];
		for (UIViewController *controller in tabBarController.viewControllers) {
            if ([controller isKindOfClass:[navcontroller class]]) {
			    [ArrayNavcontroller_title addObject: [controller title] ];
            }
		}
		[ArrayNavcontroller_title writeToFile:filePath atomically:NO];
		
		[self init_tab];
        
	}
}



#pragma mark -
#pragma mark 其他尚未使用到的方法
- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}





- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}
@end
